{% extends "base.html" %}
{% load staticfiles %}
{% block extracss %}
    <link rel="stylesheet" href="{% static 'multi-select/css/multi-select.css' %}"/>
    <link rel="stylesheet" href="{% static 'bootstrap-table/bootstrap-table.min.css' %}">
    <link rel="stylesheet" href="{% static 'daterangepicker/daterangepicker.css' %}">
{% endblock %}
{% block main-navbar %}
    <ul class="navigation main-menu" id="self-menu">
        <li>
            <a href="{% url 'rudiment:feedback' %}" class="navitem"  title="意见反馈"
               data-treeid="0"><i
                    class="menu-icon fa fa-home"></i><span class="mm-text">意见反馈</span></a>
        </li>
        <li>
            <a href="{% url 'rudiment:list_feedback' %}" class="navitem"  title="意见列表"
               data-treeid="0"><i
                    class="menu-icon fa fa-home"></i><span class="mm-text">意见列表</span></a>
        </li>
    </ul>

{% endblock main-navbar %}

{% block content %}

    <script type="text/javascript">

        $(document).ready(function(){
            $.ajaxSetup({
                 data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
            });
        $('#feedback_form').submit(function(){
                var title = $("#title").val();
                var content = $("#content").val();
                if(title!='' && content !=''){
                    $.ajax({
                        type:"POST",
                        data: {title:title, content:content},
                        url: "/submit_feedback", //后台处理函数的url 这里用的是static url 需要与urls.py中的name一致
                        dataType: "html",
                        success: function(result){
                            $("#title").val('');
                            $("#content").val('');
                            if(result==200) {
                                alertify.set('notifier', 'position', 'bottom-right');
                                alertify.success('谢谢反馈！(#^.^#)');
                            }else{
                                alertify.set('notifier','position', 'bottom-right');
                                alertify.error('反馈失败!┭┮﹏┭┮');
                            }
                        },
                        error: function(){
                            alertify.set('notifier','position', 'bottom-right');
                            alertify.error('反馈失败!┭┮﹏┭┮');
                        }
                    });
                }else{
                    alertify.set('notifier','position', 'bottom-right');
                    alertify.error('请填写内容');
                    return false;
                }
                return false;
            });
        });
</script>
    <div class="row">
    <form class="form-horizontal"  method="POST" id="feedback_form">
        {% csrf_token %}
        <legend>意见反馈表</legend>
           <div class="form-group">
              <label class="col-sm-2 control-label" for="title">标题：</label>
              <div class="col-sm-8">
                 <input class="form-control" name="title" id="title" type="text" value=""/>
              </div>
           </div>
           <div class="form-group">
              <label class="col-sm-2 control-label" for="content">内容：</label>
              <div class="col-sm-8">
                   <textarea class="form-control" rows="8" name="content" id="content"></textarea>
              </div>
            </div>
          <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-success">提交</button>
            </div>
        </div>
     </form>
    </div>
{% endblock %}

